﻿#ifndef EARTHWRAPPER_H
#define EARTHWRAPPER_H

#include <amk3/amk3.h>
#include <osgViewer/Viewer>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarth/MapNode>
#include <string>

class AMK_API EarthWrapperOptions
{
public:
    int width;
    int height;
    osgViewer::Viewer* viewer;
};


//osgEarth接口
class AMK_API EarthWrapper
{
public:
    EarthWrapper();
    //创建地图节点
    void createMapNode(std::string path);
    //初始化
    void init(const EarthWrapperOptions& op);
    //渲染函数
    void render(bool draw = true);

    inline osgViewer::Viewer* getViewer(){return _viewer.get();}
    inline osgEarth::Util::EarthManipulator* getManipulator(){return _manipulator.get();}
    inline osg::Camera* getCamera(){return _camera.get();}
    inline osgEarth::Map* getMap(){return _map;}
    inline osgEarth::MapNode* getMapNode(){return _mapNode;}

    inline osg::Vec3d& getEyePosition(){return this->_eye;}
    inline osg::Vec3d& getCenterPosition(){return this->_center;}

    //所用椭球地
    inline const osg::EllipsoidModel* getEllipsoidModel(){return _ellipsoidModel;}

    //获取Context
    //EarthContextAdapter* getGraphicContext();

    static EarthWrapper* instance();
    static void close();
    //根节点
    inline osg::Group* getRootNode(){return this->_rootNode;}

    //场景子节点
    inline osg::Group* getSceneNode(){return _sceneNode.get();}

    //非地图场景子节点
    inline osg::Group* getUnMapSceneNode(){return _sceneNode.get();}

    void setStereoMode(bool b);

    void renderStereo(int lr);

	//void resizeViewport();
    float __asp;

protected:
    osg::ref_ptr<osgViewer::Viewer> _viewer;
    osg::ref_ptr<osgEarth::Util::EarthManipulator> _manipulator;
    osg::ref_ptr<osg::Camera> _camera;
    //EarthContextAdapter* _contextAdapter;
    const osg::EllipsoidModel* _ellipsoidModel;
    osg::ref_ptr<osgEarth::MapNode> _mapNode;
    osg::ref_ptr<osgEarth::Map> _map;

    osg::ref_ptr<osg::Group> _rootNode;
    osg::ref_ptr<osg::Group> _sceneNode;
    osg::Vec3d _eye;
    osg::Vec3d _center;
    float _stereo_scale;
    double _camera_height;
    int _stereo_mode;
    int _stereo_stage;
    int _maploaded ;

};

#endif // EARTHWRAPPER_H
